package com.wfm.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.List;

public class PTwo16组合总和III{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path =new ArrayList<>();
    public List<List<Integer>> combinationSum3(int k, int n) {
        dfs(k,1,n);
        return res;
    }
    void dfs(int k,int start,int n){
        if(path.size()==k){
            if(n==0){
                res.add(new ArrayList<>(path));
            }
            return;
        }
        for (int i = start; i <=9; i++) {
            if(i>n) break;
            path.add(i);
            dfs(k,i+1,n-i);
            path.remove(path.size()-1);
        }
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new PTwo16组合总和III().new Solution();
        List<List<Integer>> lists = solution.combinationSum3(3, 7);
        System.out.println(lists);
    }
}